<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('没有任务ID','error','jy_renwushop/index/');
	}
	$renwu=pdo_get('jy_renwushop_renwu',array('id'=>$id,'status'=>1,'uniacid'=>$_SESSION['uniacid']));
	if(!$renwu){
		exi('选择的任务不存在或已下架，请重新选择！','error','/index/');
	}
	if($renwu['mid']!=$_SESSION['uid']){
		exi('您不是该任务的发布者，无权查看！','error','/index/');
	}
	$_SESSION['renwuid'] = $renwu['id'];
	$return['params']=array('status'=>0);
	$return['renwuurl']=custom_url('jy_renwushop/renwu.detail//id='.$id,true);
	$return['sharedata']=array(
		'title'=>$renwu['title'],
		'desc'=>$renwu['desc']?$renwu['desc']:$renwu['title'],
		'link'=>custom_url('jy_renwushop/renwu.detail//id='.$id.'&fromuser='.$_SESSION['uid'].'&current_plugin='.$_SESSION['current_plugin'],true),
		'imgUrl'=>tomedia($renwu['image'])
	);
	$renwu['isnum']=pdo_count('jy_renwushop_renwuorder',array('uniacid'=>$_SESSION['uniacid'],'renwuid'=>$renwu['id']),'id');
	$renwu['lastnum']=$renwu['totalnum']-$renwu['isnum'];
	$renwu['typetitle']=$this->renwu_types[$renwu['type']];
	$return['renwu']=$renwu;
	set_html('title',$renwu['title']?:'任务详情');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'renwuid'=>$_SESSION['renwuid']);
	$params['status']=intval($_RQ['status']);
	$return['params']=intval($_RQ['status']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_renwushop_renwuorder',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['statustitle']=$this->renwuorder_status[$item['status']];
		}
	}else{
		$sum=0;
	}
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='detail'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('没有订单ID','error','jy_renwushop/index/');
	}
	$order=pdo_get('jy_renwushop_renwuorder',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	if(!$order){
		exi('选择的订单不存在，请重新选择！','error','/index/');
	}
	$renwu=pdo_get('jy_renwushop_renwu',array('id'=>$order['renwuid'],'uniacid'=>$_SESSION['uniacid']));
	$renwu['hours']=$this->hours_type[$renwu['hours_type']];
	$order['subdata']=json_decode($order['subdata'],true);
	$order['subdata']['images']=$order['subdata']['images']?:array();
	$order['member']=cfc('core')->member_show($order['mid']);
	$order['createtime']=date('Y-m-d H:i:s',$order['createtime']);
	$order['subtime']=$order['subtime']?date('Y-m-d H:i:s',$order['subtime']):'';
	$order['successtime']=$order['successtime']?date('Y-m-d H:i:s',$order['successtime']):'';
	$order['statustitle']=$this->renwuorder_status[$order['status']];
	$return['post']=array('id'=>$id);
	$return['order']=$order;
	$return['renwu']=$renwu;
	exi($return);
}
if($_RQ['op']=='subdata'){
	$post=get_postdata();
	$id=intval($post['id']);
	$isstop=pdo_getcolumn('jy_renwushop_renwu',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id),'isstop');
	if($isstop){
		exi('该任务已关闭！','error');
	}
	if(!$post['desc'] && $post['status']==3){
		exi('请填写不合格提交说明！','error');
	}
	$order=array(
		'remark'=>$post['remark'],
		'status'=>$post['status'],
	);
	$this->pdo_update('renwuorder',$order,array('id'=>$id));
	if($post['status']==2){
		$this->model('member')->getfee($id);
	}
	exi('审核操作完成！');
}